package com.example.minefieldkeepercloud.interfac;

import android.content.Context;
import android.util.Log;

import com.example.minefieldkeepercloud.network.HttpUtils;
import com.example.minefieldkeepercloud.util.ToastUtil;
import com.example.minefieldkeepercloud.view.dialog.LoadingDialog;

/**
 * 重新封装网络请求接口
 */
public abstract class ApiHttpCallback extends HttpUtils.HttpCallback {
    private LoadingDialog loadingDialog;
    private Context context;
    private boolean isShowError;

    /**
     * @param context     传入当前的Activity
     * @param kind        0=不可以取消loadialog 1=可以取消
     * @param isShowError true 显示错误提示 false 不显示
     */
    public ApiHttpCallback(Context context, int kind, boolean isShowError) {
        this.context = context;
        this.isShowError = isShowError;
        loadingDialog = new LoadingDialog(context, kind);
    }

    /**
     * @param context      传入当前的Activity
     * @param
     * @param isShowError  true 显示错误提示 false 不显示
     * @param
     */
    public ApiHttpCallback(Context context, boolean isShowError) {
        this.context = context;
        this.isShowError = isShowError;

    }

    @Override
    public void onStart() {
        super.onStart();
        if (loadingDialog != null)
            loadingDialog.show();
    }

    @Override
    public void onSuccess() {
        super.onSuccess();
        if (loadingDialog != null)
            loadingDialog.dismiss();
    }

    @Override
    public void onError() {
        super.onError();
        if (loadingDialog != null)
            loadingDialog.dismiss();
    }

    @Override
    public void onSuccess(String data) {

    }

    @Override
    public void onError(String msg) {
        super.onError(msg);
        if (isShowError) {
            ToastUtil.showToast(context, msg);
            Log.i("====", "错误信息：" + msg);
        }

    }


}
